package com.usian.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.usian.ContentCategoryFeign;
import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("content")

public class ContentCategoryController {
    @Autowired
    private ContentCategoryFeign contentCategoryFeign;
    //查所有的下拉框
    @RequestMapping("selectContentCategoryByParentId")
    public Result selectContentCategoryByParentId(@RequestParam(defaultValue = "0") Long id){
        List<TbContentCategory> list =contentCategoryFeign.selectContentCategoryByParentId(id);
        if (list!=null && list.size()>0){
            return Result.ok(list);
        }
        return Result.error("啥也不说");
    }
    //insertContentCategory 下拉框增
    @RequestMapping("insertContentCategory")
    public Result insertContentCategory(Long parentId,String name){
        Integer a = contentCategoryFeign.insertContentCategory(parentId,name);
        if (a==1){
            return  Result.ok();
        }
        return Result.error("下拉框添加失败");
    }
//查询具体大广告 content/selectTbContentAllByCategoryId
    @RequestMapping("selectTbContentAllByCategoryId")
    public Result selectTbContentAllByCategoryId(Long categoryId){
      PageResult page = contentCategoryFeign.selectTbContentAllByCategoryId(categoryId);
      if (page!=null){
          return Result.ok(page);
      }
        return Result.error("查询大广告失败");
    }
    //修改下拉框  /content/updateContentCategory
    @RequestMapping("updateContentCategory")
    public Result updateContentCategory(Long id,String name){
        Integer a = contentCategoryFeign.updateContentCategory(id,name);
        if (a==1){
            return Result.ok();
        }
        return Result.error("修改下拉框错误");
    }
    //删除下拉框 content/deleteContentCategoryById
    @RequestMapping("deleteContentCategoryById")
    public Result deleteContentCategoryById(Long categoryId){
        Integer a = contentCategoryFeign.deleteContentCategoryById(categoryId);
        if (a==1){
            return Result.ok();
        }
        return Result.error("删除下拉框失败");
    }
  //具体的添加方法 content/insertTbContent
    @RequestMapping("insertTbContent")
    public Result insertTbContent(TbContent tbContent){
        Integer a = contentCategoryFeign.insertTbContent(tbContent);
        if (a!=null){
            return Result.ok();
        }
        return Result.error("具体的添加失败");
    }
    //具体的删除  content/deleteContentByIds
    @RequestMapping("deleteContentByIds")
    public Result deleteContentByIds(Long ids){
        Integer a = contentCategoryFeign.deleteContentByIds(ids);
        if (a==1){
            return Result.ok();
        }
        return Result.error("具体删除失败");
    }
}
